#pragma once

#include "Data/IRequestHander.h"
#include "AutoGen_RenderData.h"

class SimpleRenderDataRequestHandler : public data::IRequestHandler
{
public:

	SimpleRenderDataRequestHandler()
	{
		m_hsDataName = 0;
		m_pRenderData = 0;
	}

	void RequestData(cr::uint32_t hsDataName)
	{
		CR_ASSERT(m_hsDataName == 0);
		m_hsDataName = hsDataName;
		data::Manager::Get().RequestData(hsDataName, this);
	}

	void ReleaseData()
	{
		CR_ASSERT(m_hsDataName != 0);
		data::Manager::Get().ReleaseData(m_hsDataName, this);
	}

protected:

	cr::uint32_t					m_hsDataName;
	Data_RenderData::RenderData*	m_pRenderData;

private:

	void DataRequest_OnUnregisterData(cr::uint32_t hsDataName)
	{
		if (hsDataName == m_hsDataName)
		{
			m_pRenderData = 0;
		}
	}

	void DataRequest_OnRegisterData(cr::uint32_t hsDataName, data::DataBlockHeader* pHeader, void* pData)
	{
		if (hsDataName == m_hsDataName)
		{
			m_pRenderData = (Data_RenderData::RenderData*)pData;
		}
	}
};